<template>
  <!-- 行列布局：栅格布局，将一行分为 24 份，每列占多少份由 el-col 身上的 span 属性决定。 -->
  <!-- type：flex 启用弹性布局。默认是使用的浮动布局 -->
  <!-- justify：flex 布局下的水平排列方式 -->
  <!-- align：flex 布局下的垂直排列方式 -->
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%;"
  >
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <!-- trigger="click" 点击激活，默认是hover激活 -->
          <el-dropdown trigger="click">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addFn">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="$emit('showDialog', nodeData, 'edit')">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'TreeTools',
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    addFn() {
      this.$emit('showDialog', this.nodeData)
    }
  }
}
</script>
